Skip to main content

All Questions

3votes
2answers
534views

Is it okay to use Dependency injection only because of unit testing?

I have a class that has dependencies that I know are not going to change. class ConversationFinder { public function __construct( protected Conversation $conversationDbFinder = new ...
Ghassan Barghouti's user avatar
4votes
1answer
881views

Cross-cutting concerns and dependency injection

I've got a web application with an architecture somewhat like a front-controller MVC design. I get HTTP requests, route them, run them through a filter layer, dispatch them to my domain classes which ...
CXJ's user avatar
  • 187
1vote
3answers
146views

What considerations should I mind when designing methods or functions that take in a lot of parameters?

What considerations should I mind when designing methods or functions that take in a lot of parameters? A lot meaning over 4 but less than 10. Example, I am debating whether to pass in an array like ...
Dennis's user avatar
  • 8,257
0votes
1answer
217views

Which types of objects that are instantiated inside controller's methods should be injected into the controller instead?

Consider code below MyController //MyAction //MyHandler { public function processRequest() { // ... $myObject = new MyObjectClass(); $myObject->methodCall(); ...
Dennis's user avatar
  • 8,257
2votes
2answers
221views

What is wrong with writing web applications in a way that merges repository layer with view and with controller in the same file?

is there anything wrong with writing code in a way that merges view, repository, controller in the same file? i.e. global $db; // or $db = DBSingleton::get_db_instance(); // or global $container; $...
Dennis's user avatar
  • 8,257
0votes
1answer
1kviews

Dependency Injection in one method to other method params

A teammate of mine wrote some code in the following way: Class Foo implements Job { // Framework uses type-hinting for dependency injection, only works on the handle() method // not on other methods ...
Mazzy's user avatar
3votes
2answers
2kviews

Dependency Injection in Chain of Command pattern

I have a Chain of Command pattern implemented, with modules that implement an interface: interface IRequestHandler { public function handle(&$offset, &$tripData, $request = null); ...
george007's user avatar
-1votes
1answer
171views

Laravel Service Providers count and DI

I understand how service prividers in Laravel works and how to use them. But I'm not sure about how to keep clean code, specificaly in count of method parameters. For example I have this route: Route:...
Jaroslav Klimčík's user avatar
2votes
1answer
259views

How to add extra functionality to an existing method class dynamically with DI?

I am looking for the best pattern to apply in my problem. I have an interface that defines my service class functionality interface NegotiationInterface { abstract public function ...
dextervip's user avatar
2votes
2answers
932views

How to use Dependency-injection Containers correctly when they hide dependencies from outer classes?

From Zend Docs there is this example of how to use Zend\Di, which is a dependency injection container of Zend Framework: // inside a bootstrap somewhere $di = new Zend\Di\Di(); // inside each ...
Dennis's user avatar
  • 8,257
3votes
0answers
898views

Dependency injection - Nested objects

# Introduction I am working on a CMS application in PHP with about 200 classes. The CMS, in general, does the same thing every CMS does: generate sites. I am learning a lot about OOP and design ...
PIDZB's user avatar
1vote
2answers
322views

Which programming technique can trim extra code generated by Dependency Injection?

Original Class class HomeController { function __construct() { $this->setPhpRenderer('Module'); $this->repository = new HomeRepository($id); $this->...
Dennis's user avatar
  • 8,257
3votes
0answers
2kviews

Dependency Injection and class Inheritance

The project I am working on for about a year now was used to create a new mysqli connection to the database each time there was a Query to the database. In order to quickfix this problem at places ...
Tekay37's user avatar
5votes
2answers
2kviews

PHP OOP dependency injection - when is it o.k. to use the "new" statement

I was told to avoid "new" statements in classes or functions but rather create the objects from classes in the root of the program (maybe with the use of a DI-container) and then inject the objects ...
Benedikt's user avatar
5votes
2answers
2kviews

Dependency Injection & In-class Instantiation | Practical Limitations

Dependency Inversion is Good Inversion of dependency is good, it: Simplifies unit-testing Reduces coupling, allowing software components to be used interchangeably Keeps instantiation logic for a ...
user avatar

153050per page
close